import 'package:flutter/material.dart';
import 'package:top_foundation/top_foundation.dart';

import 'package:webview_flutter/webview_flutter.dart';

import '../../helper/utils/util.dart';
import 'index.dart';

class WebViewPage extends GetView<WebController> {
  const WebViewPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    return WebViewWidget(controller: controller.state.webCtrl);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<WebController>(
      builder: (_) {
        return WillPopScope(
          onWillPop: !controller.state.isWebCanBack
              ? null
              : () async {
                  return true;
                },
          child: Scaffold(
            appBar: controller.state.title == null
                ? null
                : detailAppBar(context, title: controller.state.title),
            body: controller.state.isSafeArea
                ? SafeArea(
                    child: _buildView(),
                  )
                : _buildView(),
          ),
        );
      },
    );
  }
}
